package com.tc.action;

import com.tc.dto.Envelope;
import com.tc.service.ThingsService;

public class FunAction implements FunInterface {
    private ThingsService thingsService;    //具体服务提供
    public FunAction(){
        this.thingsService=new ThingsService();
    }
    public String deal(String str) {
        Envelope env=Envelope.fromObject(str);	//首先将请求实例化，便于进一步处理
        try{
            switch (env.getCode()){
                case 1:
                    return thingsService.getAllThings(env).toString();
                case 2:
                    return thingsService.addNewThings(env).toString();
                case 3:
                    return thingsService.deleteThing(env).toString();
            }
        }catch (Exception e){
            e.printStackTrace();
            return Envelope.systemError.toString();
        }

        return new Envelope(-3,"未知服务！",null).toString();
    }
}
